package org.mspring.mlog.web.admin;

import org.mspring.mlog.cache.NodeCacheService;
import org.mspring.mlog.web.BaseAdminController;
import org.mspring.mlog.entity.NodeEntity;
import org.mspring.mlog.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * @author Gao Youbo
 * @since 2014年10月13日
 */
@Controller
@RequestMapping("/admin")
public class AdminIndexController extends BaseAdminController {
    private NodeCacheService nodeCacheService;

    @RequestMapping({"/index", "/", ""})
    public String index(HttpServletRequest request, HttpServletResponse response, Model model) {
        UserEntity user = getCurrentUser();
        List<NodeEntity> items = nodeCacheService.getTreeNode(user.getId());
        model.addAttribute("items", items);
        return "/admin/index";
    }

    @Autowired
    public void setNodeCacheService(NodeCacheService nodeCacheService) {
        this.nodeCacheService = nodeCacheService;
    }
}
